package com.helin.helinhealth.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.helin.helinhealth.entity.HealthReport;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;

/**
 * 健康报告数据访问接口
 */
@Mapper
public interface HealthReportMapper extends BaseMapper<HealthReport> {
    
    /**
     * 查询用户最近的健康报告
     * 
     * @param userId 用户ID
     * @param limit 限制数量
     * @return 健康报告列表
     */
    @Select("SELECT * FROM health_report WHERE user_id = #{userId} " +
            "AND is_deleted = 0 ORDER BY create_time DESC LIMIT #{limit}")
    List<HealthReport> getRecentReports(@Param("userId") String userId, @Param("limit") int limit);
    
    /**
     * 根据日期范围查询用户健康报告
     * 
     * @param userId 用户ID
     * @param startDate 开始日期
     * @param endDate 结束日期
     * @return 健康报告列表
     */
    @Select("SELECT * FROM health_report WHERE user_id = #{userId} " +
            "AND ((start_date <= #{endDate} AND end_date >= #{startDate}) " +
            "OR (start_date BETWEEN #{startDate} AND #{endDate})) " +
            "AND is_deleted = 0 ORDER BY create_time DESC")
    List<HealthReport> getReportsByDateRange(
            @Param("userId") String userId,
            @Param("startDate") LocalDate startDate,
            @Param("endDate") LocalDate endDate);
} 